﻿
//判断一个控件是否为空
function IsFieldEmpty(fieldName, msg) {
    var objField = document.getElementById(fieldName);
    var fieldValue = objField.value;
    //alert(str);
    //str = trim(str);
    if (fieldValue.length == 0) {
        alert(msg);
        objField.focus();
        return false;
    }
    return true;
}

//验证时间
 function isShortTime(fieldName) {
     var objField = document.getElementById(fieldName);
     var str = objField.value;
     alert(str);
    var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);  
     if (a == null) {alert('输入的参数不是时间格式'); return false;}  
     if (a[1]>24 || a[3]>60 || a[4]>60)  
     {  
         alert("时间格式不对");  
         return false 
     }  
     return true;
 }

//是否是短日期
 function isShortDate(fieldName) {
     var objField = document.getElementById(fieldName);
     var str = objField.value;
     var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
     if (r == null) {
         alert('日期格式不正确.请重新确认');
         return false; 
     }
    var d= new Date(r[1], r[3]-1, r[4]);  
    return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);  

 }

//验证完整日期
 function isLongDateTime(fieldName) {
     var objField = document.getElementById(fieldName);
     var str = objField.value; 
     var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;  
     var r = str.match(reg);
     if (r == null) {
         alert('日期时间格式不正确.请重新确认');
         return false;
     }
     var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);  
     return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5] &&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);

 }
 
 //是否是正整数
 function isInterger(fieldName) {
     var objField = document.getElementById(fieldName);
     var str = objField.value;
     var re = /^[1-9]\d*$/;
     if (!re.test(objField.value)) {
         alert("必须为正整数!");
         objField.value = "";
         objField.focus();
         return false;
     }

     return true;

 } 

 
 
